#include "sockserver.h"
#include "sockthread.h"

sockServer::sockServer(QObject *parent)
    : QTcpServer(parent)
{
    clients = 0;
}

void sockServer::incomingConnection(int socketDescriptor)
{
    clients++;
    emit( clientCountChanged( clients ) );
    sockThread *thread = new sockThread(socketDescriptor, this, path, upLimit, downLimit);
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    connect(thread, SIGNAL(finished()), this, SLOT(clientDissconnected()));
    thread->start();
}

void sockServer::setPath( QString newPath )
{
    path = newPath;
}

void sockServer::setBandwidth(int up, int down)
{
    upLimit = up;
    downLimit = down;
}

void sockServer::clientDissconnected()
{
    clients--;
    emit( clientCountChanged( clients ) );
}
